<?php

namespace app\db\controller;

use think\Controller;
use think\Cookie;
use think\Db;
use think\Exception;

class Admincontrol extends Dbcommoncontrol
{
    protected $DbName='AdminInf';
    /**
     * @var array  前置操作
     */
//    protected $beforeActionList = [
//        'checkcookie' => ['except' => 'login'],
//    ];
    public function checkcookie()
    {
        if (!Cookie::has('NumberInf','Login_')) {
          $this->error("error");
        }
    }
    public function login()
    {
        try {
            $id = $_POST["id"];
            $pwd = $_POST["pwd"];
        } catch (Exception $exception) {
            return ;
        }
        $admin = Db::table('AdminInf')->where('A_LoginId', $id)->field('A_Id,A_LoginId,A_Pwd,A_Name')->find();//找到记录
        if ($admin["A_Pwd"] != $pwd)//判断密码
            return "error pwd";
        else {
            if(Cookie::has("NumberInf"))//cookie清空后设置
                Cookie::clear("Login_");
            Cookie::prefix('Login_');
            Cookie::set("NumberInf", [$id, $pwd], 3600);
            return json($admin);
        }
    }
    public function hello()
    {
        $query = Db::query("select  * from WordInf");
        var_dump($query);
    }
}
